import serial.tools.list_ports

def list_serial_ports():
    ports = serial.tools.list_ports.comports()
    if len(ports)<=0:
        return ['无串口设备']
    else:
        available_ports = [port.device + '-' + port.description for port in ports]
        return available_ports
if __name__ == '__main__':
    print('可用串口：')
    ports = list_serial_ports()
    for port in ports:
        print(port)
    input('防止闪退，方便观察')
